package com.kcl.dfss.utils;

import android.app.Activity;
import android.content.Context;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;



public class ScreenUtils {
	
	  /** 
       * 获得当前屏幕亮度的模式     
       * SCREEN_BRIGHTNESS_MODE_AUTOMATIC=1 为自动调节屏幕亮度 
       * SCREEN_BRIGHTNESS_MODE_MANUAL=0  为手动调节屏幕亮度 
       */  
      public static int getScreenMode(Context context){  
        int screenMode=0;  
        try{  
            screenMode = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);  
        }  
        catch (Exception localException){  
              
        }  
        return screenMode;  
      }
      
      /** 
       * 获得当前屏幕亮度值  0-255 
       */  
      public static int getScreenBrightness(Context context){  
        int screenBrightness=255;  
        try{  
            screenBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);  
        }  
        catch (Exception localException){  
              
        }  
        return screenBrightness;  
      } 
      
      /** 
       * 设置当前屏幕亮度的模式     
       * SCREEN_BRIGHTNESS_MODE_AUTOMATIC=1 为自动调节屏幕亮度 
       * SCREEN_BRIGHTNESS_MODE_MANUAL=0  为手动调节屏幕亮度 
       */  
      public static void setScreenMode(int paramInt,Context context){  
        try{  
          Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, paramInt);  
        }catch (Exception localException){  
          localException.printStackTrace();  
        }  
      } 

      /** 
       * 设置系统级屏幕亮度值  0-255 
       */  
      public static void saveScreenBrightness(int paramInt,Context context){  
        try{  
          Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, paramInt);  
        }  
        catch (Exception localException){  
          localException.printStackTrace();  
        }  
      }
      
      /** 
       * 设置当前的屏幕亮度值，及时生效 0-255 
       * 该方法仅对当前应用屏幕亮度生效 
       */  
      public static void setScreenBrightness(int paramInt,Activity context){  
        Window localWindow = context.getWindow();  
        WindowManager.LayoutParams localLayoutParams = localWindow.getAttributes();  
        float f = paramInt / 255.0F;  
        localLayoutParams.screenBrightness = f;  
        localWindow.setAttributes(localLayoutParams);  
      }  
}
